<?php
/**
 * Amazon-fba每日库存报告(保留库存)
 * (amazon-model)
 */
namespace App\Models\Amazon;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\DB;

class FbaReservedInventory extends Model
{
    protected $connection = 'mysql_amazon';

    protected $table = 'fba_reserved_inventory';

    protected $guarded  = [];

    /**
     * 获取FBA保留库存
     * @param $sku
     * @param $countryId
     * @return \Illuminate\Database\Eloquent\Builder|Model|object|null
     */
    public static function getReservedInventory($sku, $countryId){
        return self::query()
            ->select(DB::raw('sum(IFNULL(reserved_fc_transfers,0) + IFNULL(reserved_fc_processing,0)) as reserved_quantity'))
            ->where('country_id',$countryId)
            ->where('sku', $sku)
            ->first();
    }

}
